﻿
using System;
using System.ComponentModel;
using System.Reflection;
namespace Common
{
    public class EnumHelper
    {
        /// <summary>
        /// 表基本字段
        /// </summary>
        public enum BaseField
        {
            ID,
            CreateUserID,
            LastUpdateUserID,
            CreateDate,
            LastUpdateDate,
            IsDeleted,
            Sort
        }
        /// <summary>
        /// 审核状态
        /// </summary>
        public enum EnumCheck
        {
            待审核 = 1,
            审核通过 = 2,
            被驳回 = 3
        }
        /// <summary>
        /// 数据字典分类
        /// </summary>
        public enum EnumDictionaryType
        {
            审核状态 = 1,
            会议预约类型 = 2,
            部门管理 = 3,
            会议详细状态 = 4,
            页面分类 = 5,
            资料库附件类型 = 6
        }
        /// <summary>
        /// 页面分类
        /// </summary>
        public enum EnumPageType
        {
            列表页 = 35,
            表单页 = 36,
            明细页 = 37
        }
        /// <summary>
        /// 系统角色
        /// </summary>
        public enum EnumRole
        {
            /// <summary>
            /// 超级管理员
            /// </summary>
            Admin = 1,
            /// <summary>
            /// 技术支持
            /// </summary>
            Tech = 2,
            /// <summary>
            /// 普通用户
            /// </summary>
            User = 3
        }

        /// <summary>
        /// 发送短信模板
        /// </summary>
        public enum SendTemplate
        {
            /// <summary>
            /// 测试站点访问
            /// </summary>
            TestAccess = 13436,
            /// <summary>
            /// 验证码
            /// </summary>
             IdentifyingCode = 27782
           
        }

        /// <summary>
        /// 测试类型
        /// </summary>
        public enum ExamType
        {
            /// <summary>
            /// 调研
            /// </summary>
            Survey = 0,
            /// <summary>
            /// 考试
            /// </summary>
            Examination = 1,
            /// <summary>
            /// 投票
            /// </summary>
            Vote = 3
        }

        public static class Extentions
        {
            public static string GetName(System.Type t, object v)
            {
                try
                {
                    return Enum.GetName(t, v);
                }
                catch
                {
                    return "UNKNOWN";
                }
            }
            /// <summary>
            /// 返回指定枚举类型的指定值的描述
            /// </summary>
            /// <param name="t">枚举类型</param>
            /// <param name="v">枚举值</param>
            /// <returns></returns>
            public static string GetDescription(System.Type t, object v)
            {
                try
                {
                    if (v == null)
                    {
                        return string.Empty;
                    }
                    FieldInfo fi = t.GetField(GetName(t, v));
                    DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    return (attributes.Length > 0) ? attributes[0].Description : GetName(t, v);
                }
                catch
                {
                    return "UNKNOWN";
                }
            }
        }
    }
}
